//////////////////////////////////////////////////////////////////////////
// MessageHandler.cpp													//
//																		//
// WYJ																	//
// 2010.4																//
//																		//
//////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "MessageHandler.h"
#include "ConnecterManager.h"

MessageHandler::MessageHandler( ConnecterManager * pConnecterManager )
: m_pConnecterManager( pConnecterManager )
{
}

MessageHandler::~MessageHandler( void )
{
}

void MessageHandler::HandleMessage( int index, const char * msg )
{
	MessageHead* pMessage = (MessageHead *)msg;
	if ( pMessage->msgCate != MsgCategory::MYSQL_TEST )
	{
		char buf[1024];
		sprintf_s( buf, 1024, "Receive a undefine message category(%x)", pMessage->msgCate );
		MessageBox( NULL, buf, 0, 0 );
		return;
	}
	switch ( pMessage->msgType )
	{
	case MsgType::None:
		{
			char buf[1024];
			sprintf_s( buf, 1024, "Receive a message type is None(%x)", pMessage->msgType );
			MessageBox( NULL, buf, 0, 0 );
			return;
		}
		break;
	case MsgType::Init:
		HandleInitMessage( index, pMessage );
		break;
	case MsgType::Ready:
		break;
	case MsgType::Running:
		break;
	case MsgType::Stop:
		break;
	case MsgType::Sucess:
		break;
	case MsgType::Interrupt:
		break;
	default:
		{
			char buf[1024];
			sprintf_s( buf, 1024, "Receive an undefine message type(%x)", pMessage->msgType );
			MessageBox( NULL, buf, 0, 0 );
			return;
		}
		break;
	}
}

void MessageHandler::HandleInitMessage( int index, const MessageHead* pMessage )
{
	Msg_Init* pMsg = (Msg_Init *)pMessage;

	m_pConnecterManager->InitConnecter( index, pMsg->threadID );
}